﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Student_Enroll : System.Web.UI.Page
{
    List<HocPhan> dangky = new List<HocPhan>();

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            Label8.Visible = false;
            StaticVariables.dangky.Clear();
            GridView2.DataSource = new DanhsachHocPhan().danhsachTH;
            GridView2.DataBind();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        if (RadioButtonList1.SelectedValue == "10")
        {
            StaticVariables.dangky.AddRange(new DanhsachHocPhan().danhsach10);
            GridView3.DataSource = StaticVariables.dangky;
            GridView3.DataBind();
        }
        else if (RadioButtonList1.SelectedValue == "11")
        {
            StaticVariables.dangky.AddRange(new DanhsachHocPhan().danhsach11);
            GridView3.DataSource = StaticVariables.dangky;
            GridView3.DataBind();
        }
    }
    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
            string mahp = e.CommandArgument.ToString();

            List<HocPhan> th = new DanhsachHocPhan().danhsachTH;
            HocPhan hocphan = null;
            foreach (HocPhan item in th)
            {
                if (item.mahp == mahp)
                {
                    hocphan = item;
                    break;
                }
            }

            if (hocphan != null)
            {
                bool add = true;
                foreach (HocPhan item in StaticVariables.dangky)
                {
                    if (item.mahp == mahp)
                        add = false;
                }
                if (add)
                {
                    StaticVariables.dangky.Add(hocphan);
                    GridView3.DataSource = StaticVariables.dangky;
                    GridView3.DataBind();
                }
            }
        }

    }

    protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "Delete_Course")
        {
            string mahp = e.CommandArgument.ToString();
            int id = -1;
            for (int i = 0; i < StaticVariables.dangky.Count; i++)
            {
                HocPhan item = StaticVariables.dangky.ElementAt(i);
                if (item.mahp == mahp)
                {
                    id = i;
                    break;
                }
            }

            if (id != -1)
            {
                StaticVariables.dangky.RemoveAt(id);
                GridView3.DataSource = StaticVariables.dangky;
                GridView3.DataBind();
            }
        }


    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Label8.Visible = true;
    }
    protected void GridView3_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }
}